<template>
    <div class="index-lists">
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="客户等级" prop="clientGradeid">
                    <el-select v-model="queryParams.clientGradeid" class="w-[280px]" clearable>
                        <el-option label="全部" value="" />
                        <el-option label="一般客户" value="1" />
                        <el-option label="重要客户" value="2" />
                        <el-option label="潜在客户" value="3" />
                        <el-option label="个人" value="4" />
                        <el-option label="企业" value="5" />
                        <el-option label="中介" value="6" />
                        <el-option label="中型客户" value="7" />
                        <el-option label="人型客户" value="8" />
                        <el-option label="中型客户" value="9" />
                        <el-option label="小型客户" value="10" />
                        <el-option label="一级-新" value="11" />
                        <el-option label="一级-老" value="12" />
                        <el-option label="二级-新" value="13" />
                        <el-option label="二级-老" value="14" />
                        <el-option label="三级-新" value="15" />
                        <el-option label="三级-老" value="16" />
                    </el-select>
                </el-form-item>
                <el-form-item label="转入公海时间" prop="openSeaTime">
                    <daterange-picker
                        v-model:startTime="queryParams.createTimeStart"
                        v-model:endTime="queryParams.createTimeEnd"
                    />
                </el-form-item>
                <el-form-item label="前业务人员" prop="oldBusinessStaffid">
                    <el-select v-model="queryParams.oldBusinessStaffid" class="w-[280px]" clearable>
                        <el-option label="张三" value="1" />
                        <el-option label="李四" value="2" />
                        <el-option label="王五" value="3" />
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <div>
                <el-button v-perms="['highseas:add']" type="primary" @click="handleAdd()">
                    <template #icon>
                        <icon name="el-icon-Plus" />
                    </template>
                    新增
                </el-button>
                <el-button v-perms="['thread:add/edit']" type="primary">
                    <template #icon>
                        <icon name="el-icon-download" />
                    </template>
                    导出
                </el-button>
                <el-button v-perms="['thread:add/edit']" type="primary">
                    <template #icon>
                        <icon name="el-icon-upload" />
                    </template>
                    导入
                </el-button>
            </div>
            <el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists" stripe>
                <el-table-column type="selection" width="55" />
                <el-table-column label="" prop="id" min-width="70" sortable />
                <el-table-column label="客户等级" prop="clientGrade" min-width="130" sortable />
                <el-table-column label="转入公海时间" prop="openSeaTime" min-width="180" sortable />
                <el-table-column
                    label="前业务人员"
                    prop="oldBusinessStaff"
                    min-width="130"
                    sortable
                />
                <el-table-column label="客户名称" prop="clientName" min-width="130" sortable />
                <el-table-column label="客户责任人" prop="clientWho" min-width="130" sortable />
                <el-table-column label="联系电话" prop="phone" min-width="130" sortable />
                <el-table-column label="邮件" prop="mail" min-width="130" sortable />
                <el-table-column label="公海池" prop="openSeaPool" min-width="130" sortable />
                <el-table-column label="操作" width="120" fixed="right">
                    <template #default="{ row }">
                        <el-button
                            v-perms="['highseas:edit']"
                            type="primary"
                            link
                            @click="handleEdit(row)"
                        >
                            编辑
                        </el-button>
                        <el-button
                            v-perms="['highseas:del']"
                            type="danger"
                            link
                            @click="handleDelete(row.id)"
                        >
                            删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
        <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
    </div>
</template>
<script lang="ts" setup name="highseas">
import { highseasDelete, highseasLists } from '@/api/highseas'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const queryParams = reactive({
    clientGradeid: '',
    openSeaTimeStart: '',
    openSeaTimeEnd: '',
    oldBusinessStaffid: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: highseasLists,
    params: queryParams
})

const handleAdd = async () => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('add')
}

const handleEdit = async (data: any) => {
    showEdit.value = true
    await nextTick()
    editRef.value?.open('edit')
    editRef.value?.getDetail(data)
}

const handleDelete = async (id: number) => {
    await feedback.confirm('确定要删除？')
    await highseasDelete({ id })
    feedback.msgSuccess('删除成功')
    getLists()
}

getLists()
</script>
